<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('组装单')" />
	<th:block th:include="include :: list-css" />
	<style type="text/css">
        .layui-tab-title{border-color: #ccc !important;}
		.layui-this{color: rgb(0, 135, 250) !important;background: none !important;}
        .layui-tab-brief > .layui-tab-title .layui-this:after, .layui-tab-brief > .layui-tab-more li.layui-this:after{border-color:  rgb(0, 135, 250) !important;}
		label.layui-form-label {width: 95px;padding-right: 0px;}
		.layui-form-radio {margin-top:0}
        .mid-content{overflow-y:auto}
		.importTable{empty-cells:show;border-collapse:collapse;border-spacing:0;}
		.listext th{background:#eee;color:#3366cc;}
		.listext th,.listext td{border:solid 1px #ddd;text-align:left;padding:10px;font-size:14px;}
		#importProgress {z-index:20200202;background-color: #000;opacity: 0.3;display:none;}
		.importProgress {width:300px;z-index:20202222;position: fixed;top: 34%;left: 40%;display:none;}
		.istype1{height: 28px;line-height: 28px;}
		.istype2{display: none;height: 28px;line-height: 28px;display: inline-block;}
		tr img{width: 30px !important;height: 30px !important;margin: 0 2px;}
		.ishide{display: none;}
		.bagimg{z-index: 999;max-width:200px;border: 5px solid #23b971}
	</style>
	
	<!-- 打印控件 -->
	<script src="/js/printWorld/PrintWorld.js"></script>
</head>
<body>
<div class="ishide"><img class="bagimg" src=""/></div>
<div class="main-content">
	<div class="content-right">
		<div class="search-top">
			<span>查询条件</span>
			<a href="javascript:;" layadmin-event="flexible" class="menuBtn">
				<i class="layui-icon layui-icon-spread-left" id="LAY_app_flexible" style="color: #fff;"></i>
			</a>
		</div>
		<div class="panel layout-expand layui-expand-east">
		    <div class="panel-header">
		        <div class="panel-tool" style="text-align: center; width: 26px;height: 30px;line-height: 30px;">
		            <a href="javascript:;" layadmin-event="flexible" class="menuBtn">
		                <i class="layui-icon layui-icon-shrink-right" id="LAY_app_flexible" style="color: #fff;"></i>
		            </a>
		        </div>
		    </div>
		    <div class="panel-body panel-title" style="text-align: center; width: 26px;">查<br>询<br>条<br>件</div>
		</div>
       	<form class="layui-form">
			<th:block th:include="listinclude :: searchRight('page')" />
		</form>
   	</div>
    <div class="mid-content">
        <div class="layui-tab layui-tab-brief istype" lay-filter="demo1" style="margin-top: 0;">
            <ul class="layui-tab-title" >
              <li class="layui-this">未组装</li>
              <li>已组装</li>
            </ul>
            <div class="layui-tab-content"></div>
          </div>
        <table class="layui-hide" id="dhtable" lay-filter="ftable"></table>
        <div class="spxx" style="display: none;">
            <div class="layui-tab layui-tab-brief demo2" lay-filter="demo2" style="position:relative;">
                <ul class="layui-tab-title">
                  <li class="layui-this">商品信息</li>
                  <li>操作日志</li>
                </ul>
                <!-- <button style="position:absolute;right:10px;top:5px;height: 30px;line-height: 30px;" class="layui-btn layui-btn-normal zjbcbtn">保存</button> -->
                <div class="layui-tab-content"></div>
            </div>
            <table class="layui-hide" id="pdhtable" lay-filter="pftable"></table>
        </div>

    </div>
</div>
<!-- 表格头部工作栏-->
<script type="text/html" id="toolbar">
	<div class="layui-btn-container">
        <span class="ishide1">
            <div class="layui-btn layui-table-tools importbtn-bg smzzbtn" lay-event="smzzbtn" th:if="${extraButton.smzzbtn}">
                <i class="dhicon layui-icon-search"></i> 扫码组装
            </div>
			<div class="layui-btn layui-table-tools importbtn-bg zzqdbtn" lay-event="zzqdbtn" th:if="${extraButton.zzqdbtn}">
				<i class="dhicon layui-icon-print"></i> 组装清单打印
			</div>
            <!-- <div class="layui-btn layui-table-tools importbtn-bg sgzzbtn" lay-event="sgzzbtn" th:if="${extraButton.sgzzbtn}">
                <i class="dhicon layui-icon-set-fill"></i> 手工组装
            </div> -->
<!--             <div class="layui-btn layui-btn-normal layui-table-tools ishide" id="shbtn" lay-event="shbtn" th:if="${extraButton.shbtn}">-->
<!--                 <i class="dhicon dh-zu4491"></i> 审核-->
<!--		    </div>-->
<!--            <div class="layui-btn layui-table-tools importbtn-bg sgtrbtn" lay-event="sgtrbtn" shiro:hasPermission="storage:productassemble:view">-->
<!--                <i class="dhicon layui-icon-prev"></i> 数据填入-->
<!--            </div>-->
            <div class="layui-btn layui-table-tools importbtn-bg sjdrbtn" onclick="importBtn()"  lay-event="sjdrbtn" th:if="${extraButton.sjdrbtn}">
                <i class="dhicon layui-icon-print"></i> 数据导入
            </div>
            <div class="layui-btn layui-btn-danger layui-table-tools delbtn" onclick="remove()" th:if="${extraButton.delbtn}">
                <p class="dhicon dh-remove" style="color:white;font-size:14px"><span class="fa_span">批量删除</span></p>
            </div>
        </span>

        <span class="isshow">
            <div class="layui-btn layui-table-tools importbtn-bg htbtn" lay-event="htbtn" th:if="${extraButton.htbtn}">
                <i class="dhicon layui-icon-prev"></i> 回退
            </div>
			<div class="layui-btn layui-table-tools costbtn" lay-event="costbtn" onclick="costbtn()" th:if="${extraButton.costbtn}">
				<i class="dhicon dh-random"></i> 组装费用
			</div>
        </span>
		<div class="layui-btn layui-table-tools importbtn-bg" lay-event="exportbtn" th:if="${extraButton.exportbtn}">
			<i class="dhicon dh-download"></i> 导出
        </div>
		<div class="layui-btn layui-table-tools importbtn-bg rkbbtn" lay-event="rkbbtn">
			<i class="dhicon layui-icon-print"></i> 入库箱标打印
		</div>
    </div>
</script>
<!-- 表格操作区 -->
<script type="text/html" id="barDh">
    <a class="layui-btn layui-btn-danger layui-btn-xs istype1" onclick="sgzzbtn('{{d.nid}}',1)" th:if="${extraButton.sgzzbtn}">手工组装</a>
	<a class="layui-btn layui-btn-disabled layui-btn-xs istype1" th:if="!${extraButton.sgzzbtn}">手工组装</a>
	<a class="layui-btn layui-btn-danger layui-btn-xs istype2" onclick="sgzzbtn('{{d.nid}}',0)">查看详情</a>
</script>

<!-- 表格操作区 -->
<script type="text/html" id="yybl">
	<div class="layui-form layui-card-header layuiadmin-card-header-auto tccon">
		<div class="layui-form-item margin_t0">
            <input  type="hidden"  name="czguid" id="czguid"  th:value="${cost?.guid}" class="layui-input canntEdit" autocomplete="off" readonly/>
	        <div class="layui-inline margin_r0 layui-col-xs12">
	        	<label class="layui-form-label"><font>组装费用：</font></label>
				<div class="layui-input-block"><input  type="number"  name="assembleCost" id="assembleCost" th:value="${cost?.assembleCost}" class="layui-input" autocomplete="off"/></div>
			</div>
        </div>
	</div>
</script>
<script type="text/template" id="importTpl">
	<form enctype="multipart/form-data" class="mt20 mb10">
		<div class="col-xs-offset-1">
			<input type="file" id="file" name="file"/>
			<div class="mt10 pt5">
				<a onclick="$.tablelist.importTemplate('/storage/productassemble/exporttemplate')" class="btn btn-default btn-xs"><i class="dhicon dh-file-excel-o"></i> 下载模板</a>
			</div>
			<font color="red" class="pull-left mt10">提示：仅允许导入“xls”或“xlsx”格式文件！</font>
		</div>
	</form>
</script>
<script type="text/html"  id="file2_img">
	{{# if(d.img){ }}
	<img src="{{d.img}}"/>
	{{# }else{ }}
	{{# } }}
</script>
<script type="text/html"  id="file2_img1">
	{{# if(d.img1){ }}
	<img src="{{d.img1}}"/>
	{{# }else{ }}
	{{# } }}
</script>
<script type="text/html"  id="file2_img2">
	{{# if(d.img2){ }}
	<img src="{{d.img2}}"/>
	{{# }else{ }}
	{{# } }}
</script>
<!-- 导入明细 -->
<div id="iTable" class="display_no">
	<table class="importTable listext" data-resizable-columns-id="demo-table">
		<tbody id="itbody"></tbody>
	</table>
</div>


<th:block th:include="include :: footer" />
<th:block th:include="include :: businessJS" />
<th:block th:include="include :: searchJS" />
<th:block th:include="listinclude :: list-templeat" />
<script th:inline="javascript">
	/*<![CDATA[*/
	var prefix = ctx + "storage/productassemble";
    var tableUrl="/storage/productassemble/list?effectStock=0";
	var gridColumns = [[${gridColumns}]],
		importFields =[[${importFields}]],
		extraButton = [[${extraButton}]],
		moduleTable =[[${moduleTable}]];

	/*]]>*/
</script>
<script type="text/javascript">
var element,thStr;
var fieldWidth = {},		//导入列表字段宽度
	filedRequired = {},		//导入列表必填字段
	dateFiled = [],			//导入列表日期字段
	hasNull = false;		//导入数据必填字段有空值
$.each(gridColumns.dictionaryForPageFieldList,function(i,v){
	fieldWidth[v.fields] = v.fieldFrontWidth
	if(v.fieldFrontRequired)filedRequired[v.fields] = v.fieldName;
	if(v.fieldFrontType == 't_date')dateFiled.push(v.fields);
})
var $,layer,laydate,form,table,wherestr={};
layui.use(['table','laydate','form','layer','jquery','element'], function () {
	$ = layui.$, layer = layui.layer,laydate = layui.laydate , form = layui.form, table = layui.table, element = layui.element;
	serachRender();//查询条件初始渲染集合
	changeDropdown('fSl');//导入窗口——税率下拉可编辑赋事件
    var isbtn=true
	$.tablelist.init({
		elem: '#dhtable'
		,modalName: "产品信息"
		,url: tableUrl
		,updateUrl: prefix + "/edit?guid={id}"
		,initSort: {field: 'createTime',type: 'asc'}
		,totalRow: gridColumns.totalRow
		,cols: [gridColumns.gridBody]
		,toolbar: '#toolbar'
		,defaultToolbar: [{title:'列设置',layEvent: 'fieldSet',icon: 'layui-icon-set'}] //这里在右边显示
        ,parseData: function(res){ //res 即为原始返回的数据
			var objpage=sessionStorage.getItem(moduleTable+'checkdata')
			if(objpage){
				objpage=JSON.parse(objpage)
				res.data.map((v,i)=>{
					objpage.map((n,m)=>{
						if(v.guid==n.guid){
							v.LAY_CHECKED=true
						}
					})
				})
			}
		}
        ,done:function(res, curr, count){
			firstimg()
			var ltv=this.elem.next('.layui-table-view');//当前table的dom
			res.data.length || count || ltv.find('.layui-table-header').css('display', 'inline-block');//数量为0时(统计报表存在不传count的情况)，表头赋予样式可拉动
			res.data.length || count || ltv.find('.layui-table-box').css('overflow-x', 'auto');//数量为0时(统计报表存在不传count的情况)，表头赋予样式可拉动
			if($('.spxx').is(':hidden')){
				$('.layui-table-body').eq(0).css('height', "75vh");
			}else{
				$('.layui-table-body').eq(0).css('height', "40vh");
			}
            if(!isbtn){
		    	$('.ishide1').hide()
		    	$('.isshow').show()

				$('.istype2').show()
			    $('.istype1').hide()
		    }else{
                $('.ishide1').show()
		    	$('.isshow').hide()

				$('.istype1').show()
			    $('.istype2').hide()
		    }
			fixTotal(this);//修复合计行固定列问题
			rowheight(res, curr);//修复合计行固定列问题
			if(typeof listTableDone == 'function')listTableDone();//如果查询列表存在表格加载完成回调事件，则执行
		}
	});
	//监听排序事件
	table.on('sort(ftable)', function(obj){
		$.tablelist.sort('dhtable',obj);
	});

	//监听行双击事件
    table.on('rowDouble(ftable)', function (obj) {
		// top.layui.index.openTabsPage(prefix+ "/edit?nid="+obj.data.nid,'组装单 - 修改')
    });


	window.sgzzbtn=function(nid,enableEdit){
		top.layui.index.openTabsPage(prefix+ "/edit?nid="+nid+'&enableEdit='+enableEdit,'组装单 - 修改')
	}


    // 多选赋值
    sessionStorage.setItem(moduleTable+'checkdata','')
    table.on('checkbox(ftable)', function(obj){
		var objpage=sessionStorage.getItem(moduleTable+'checkdata')
		if(obj.type=='all'){//判断是否全选
			var objdata=table.checkStatus('dhtable')
			objdata=objdata.data
			if(obj.checked){//判断是否选中
				if(objpage){
					objpage=JSON.parse(objpage)
					objpage=objpage.concat(objdata)
					objpage=newData(objpage)
				}else{
					objpage=objdata
				}
			}else{
				var objpage=JSON.parse(objpage)
				var deldata=table.cache.dhtable
				objpage=delData(objpage,deldata)
			}
			sessionStorage.setItem(moduleTable+'checkdata',JSON.stringify(objpage))
		}else{//点击复选框
			if(objpage){
				objpage=JSON.parse(objpage)
				if(obj.checked){
					objpage.push(obj.data)
				}else{
					objpage.map((v,i)=>{
						if(v.guid==obj.data.guid){
							objpage.splice(i,1)
						}
			    	})
			    }
			}else{
				objpage=[]
				objpage.push(obj.data)
			}
			sessionStorage.setItem(moduleTable+'checkdata',JSON.stringify(objpage))
		}
	});
     //头工具栏事件
	// $('.zjbcbtn').click(function(){
	// 	  $.post(prefix+'/editpost',{'infoItems':JSON.stringify(table.cache.pdhtable)}, function(res){
	// 		layer.msg(res.msg);
	// 	});
	// })
	var zzdType=0
// 头部组装切换
    element.on('tab(demo1)', function(elem){
        zzdType=elem.index
        if(elem.index==1){
			tableUrl=tableUrl.replace(/0/g,'1')
			$('.istype2').show()
			$('.istype1').hide()
		}else{
			tableUrl=tableUrl.replace(/1/g,'0')
			$('.istype1').show()
			$('.istype2').hide()
		}
		table.reload('dhtable',{url:tableUrl});
		if(!$('.spxx').is(':hidden')){
			$('.spxx').hide()
			$('.layui-table-body').eq(0).css('height', "75vh");
		}

		if(elem.index==1){
            isbtn=false
			$('.ishide1').hide()
			$('.isshow').show()
		}else{
            isbtn=true
			$('.ishide1').show()
			$('.isshow').hide()
		}
	});
    // 底部信息切换
    element.on('tab(demo2)', function(elem){
		if(elem.index==1){
			oplog(comguid)
		}else{
			pddata(comobj)
		}
	});

	function pddata(obj){
		var colslist=[
		   {width: "45", type: "numbers", fixed: "left"},
 	       {field: 'sonStorageID',title: '采购入库单号',width:200},
 	       {field: 'sonOrderID',title: '采购订单单号',width:150},
 	       {field: 'vGsBm',title: '采购公司编码',width:150},
 	       {field: 'vGsJc',title: '采购公司简称',width:150},
 	       {field: 'productID',title: '商品编码',width:150},
 	       {field: 'productName',title: '商品名称',width:150},
 	       // {field: 'fNSKU',title: 'FNSKU',width:150},
 	       {field: 'sonCode',title: '子件编码',width:150},
 	       {field: 'sonName',title: '子件名称',width:150},
 	       {field: 'sonNum',title: '子件采购总数',width:150},
 	       {field: 'sonBalance',title: '子件组装剩余总数',width:150},
 	       {field: 'sonActualBalance',title: '子件组装总数',width:150},
 	       {field: 'vHw',title: '货位编码',width:150},
 	       {field: 'vKq',title: '库区',width:150},
 	       {field: 'gDepot',title: '所在仓库',width:150}
	    ]
		$('.demo2 .layui-tab-title li').removeClass('layui-this')
		$('.layui-tab-title li').attr('style','background:#fff;color:#666666');
		$('.demo2 .layui-tab-title li').eq(0).addClass('layui-this')
		$.get('/storage/productassemble/sonlist',{bid:obj.data.bid},function(res){
            var datalist=res.data.sonList
			$.tablelist.init({
				 elem: '#pdhtable'
				 // ,url: prefix+'/sonlist?pGuid='+obj.data.guid
				 ,data:datalist
				 ,limit: 99999
				 ,where: getWherestr()
				 ,totalRow:false
				 ,cols: [colslist]
				 ,defaultToolbar: [{title:'列设置',layEvent: 'fieldSet',icon: 'layui-icon-set'}]
				 ,page:false
				 // ,height:moduleTable==''?'full-46':''
				 ,parseData: function(res){ //res 即为原始返回的数据
					 return {
						 "code": res.code, //解析接口状态
						 "msg": res.msg, //解析提示文本
						 "count": res.count, //解析数据长度
						 "data": decimalToFixed(res.data,gridColumns.decimalObj) //表格数据数值类型重赋值
					 }
				 }
				 ,done:function(res, curr, count){
					 var ltv=this.elem.next('.layui-table-view');//当前table的dom
					 res.data.length || count || ltv.find('.layui-table-header').css('display', 'inline-block');//数量为0时(统计报表存在不传count的情况)，表头赋予样式可拉动
					 res.data.length || count || ltv.find('.layui-table-box').css('overflow-x', 'auto');//数量为0时(统计报表存在不传count的情况)，表头赋予样式可拉动
					 res.data.length || count || ltv.find('.layui-table-body').css('height', ltv.find('.layui-table-body').height()-17);//数量为0时，表格高度减少滚动条高度
					 $('.spxx').show()
					 $('.layui-table-body.layui-table-main').eq(0).css('height', "35vh");
                     $('.layui-table-body.layui-table-main').eq(1).css('height', "30vh");
                     $('.layui-table-body').eq(1).css('height', "calc(35vh - 15px)");
					 fixTotal(this);//修复合计行固定列问题
					 if(typeof listTableDone == 'function')listTableDone();//如果查询列表存在表格加载完成回调事件，则执行
				 }
				 ,jump:function(obj, first){
				 }
			})
		})
	}


    //单击选中行
	var comguid,comobj
	table.on('row(ftable)', function(obj){
		comguid=obj.data.guid
		comobj=obj
		pddata(obj)
		// form.render();
	});

	window.costbtn=function (){
        layer.open({
            type: 1,
            content: $('#yybl').html(),
            area: ['350px', '170px'],
            maxmin: true,
            shade: 0.3,
            title: '组装费用',
            shadeClose: true,
            btn: ['确定', '关闭'],
            yes: function(index, layero){
                var guid=$('#czguid').val()
                var assembleCost=$('#assembleCost').val()
                // if(!assembleCost) return layer.msg('请填写拆装费用')
                $.post("/storage/othercost/editpost",{'infoItems':JSON.stringify({guid,assembleCost})},function(res){
                    layer.msg(res.msg)
                    if(res.code==0){
                        location.reload();
                    }
                });
            }
        });
    }

	//头工具栏事件
 	table.on('toolbar(ftable)', function(obj){
 	    switch(obj.event){
            case 'sgzzbtn'://手工组装
			        var objpage=sessionStorage.getItem(moduleTable+'checkdata')
					if(!objpage){
						layer.msg("请先选择数据！");
					}else{
						$.modal.confirmCom('确定要组装么？',function(result){
					    	var infoItems=JSON.parse(objpage)
							var dataAll=[]
							$.each(infoItems,function(i,v){
								dataAll.push({'guid':v.guid,'effectStock':'1'})
							})
					    	$.operate.post(prefix+'/updateType',{infoItems:JSON.stringify(dataAll)},function(result){
					    		setTimeout(function(){
									sessionStorage.setItem(moduleTable+'checkdata','')
					    			table.reload('dhtable', {page: {curr: 1},where:getWherestr()});
					    		}, 1000);
					    	});
					    });
					}
				break;
			case 'zzqdbtn'://组装清单打印
				var objpage=sessionStorage.getItem(moduleTable+'checkdata')
				if(!objpage || objpage == '[]'){
					layer.msg("请至少选择一条数据！");
					break;
				}
				var infoItems=JSON.parse(objpage);
				/*
				if(infoItems.length > 1) {
					layer.msg("只能选择一条数据！");
					break;
				}
				*/
				var bids = '';
				for(var i=0; i<infoItems.length; i++) {
					bids = bids + infoItems[i].bid + ',';
				}
				bids = bids.substring(0, bids.length - 1);
				$.operate.post('/storage/productassemble/generateZuzhuangPDF',{bids: bids},function(result){
					console.log(result);
					if (result.code == 0){
						window.open(result.msg)
					}
				});
				break;
			case 'htbtn'://回退
			        var objpage=sessionStorage.getItem(moduleTable+'checkdata')
					if(!objpage){
						layer.msg("请先选择数据！");
					}else{
						$.modal.confirmCom('确定要回退么？',function(result){
					    	var infoItems=JSON.parse(objpage)
							var dataAll=[]
							$.each(infoItems,function(i,v){
								dataAll.push({'nid':v.nid,'bid':v.bid,'effectStock':'0'})
							})
					    	$.operate.post(prefix+'/updateType',{infoItems:JSON.stringify(dataAll)},function(result){
					    		setTimeout(function(){
									sessionStorage.setItem(moduleTable+'checkdata','')
					    			table.reload('dhtable', {page: {curr: 1},where:getWherestr()});
					    		}, 1000);
					    	});
					    });
					}
				break;
	   		case 'exportbtn':
		   		$.ajax({
		   		    url: '/storage/productassemble/export?effectStock='+zzdType,
		   		    type: 'GET',
		   		    data: getWherestr(),
		   		    dataType: 'json',
		   		    beforeSend: function(){
			   			showloadings(true);
		   		    },
		   		    success: function(result){
		   		    	if (result.code == 0) {
					        window.location.href = ctx + "common/download?fileName=" + encodeURIComponent(result.msg) + "&delete=" + true;
					        parent.$('.page-loading').hide();//页面进行了跳转刷新，需要手动关闭页面的加载动画
						} else if (result.code == web_status.WARNING) {
		                   $.modal.alertWarning(result.msg)
		            	} else {
							$.modal.alertError(result.msg);
						}
				   		showloadings(false);
		   		    }
		   		});
	   		break;
			case 'tableFull'://表格展开
				$('.north .layui-form').hide();
				table.reload('dhtable',{
					defaultToolbar: [{title:'收缩',layEvent:'tableShrink',icon:'layui-icon-screen-restore'}],
					height: $(window).height()-$('.north').height()-60<300?'300':$(window).height()-( $('.north').height()+$('.south').height()+12)
				});
			break;
			case 'tableShrink'://表格收缩
				$('.north .layui-form').show();
				table.reload('dhtable',{
					defaultToolbar: [{title:'展开',layEvent:'tableFull',icon:'layui-icon-screen-full'}],
					height: $(window).height()-$('.north').height()-60<300?'300':$(window).height()-( $('.north').height()+$('.south').height()+12)
				});
			break;
			case 'rkbbtn'://入库箱标打印
				var objpage=sessionStorage.getItem(moduleTable+'checkdata')
				if(!objpage || objpage == '[]'){
					layer.msg("请选择一条数据！");
					break;
				}
				var infoItems=JSON.parse(objpage);
				if(infoItems.length > 1) {
					layer.msg("只能选择一条数据！");
					break;
				}
				$.operate.post('/storage/productassemble/generateCgrkPDF',{bid: infoItems[0].bid},function(result){

					var urlBegin = window.location.href.split("//")[0];
					var json = {};
					json.action = "previewfile";	//打印指令动作。json.action = "preview"，则生成预览。
					json.format = "pdf_url";        //指定格式为pdf_url。
					json.paperwidth = 10;
					json.paperlength = 10;
					
					json.content = urlBegin + "//" + window.location.host + result.msg;   //pdf文件的url路径
					json.cert = urlBegin + "//" + window.location.host + "/js/printWorld/pdf_mini-ease.com.ctf";
					var pw = GetPrintWorld();    //获取打天下对象
					pw.Act(json);
				});
				break;
	 	    case 'fieldSet':
 	    		filedSet(moduleTable);
          	break;
 	    };
 	});

	window.importBtn=function(){
		if (importFields) {
			thStr = '<tr><th><div style="width:30px;">序号</div></th>';
			$.each(importFields, function (i, val) {
				fieldWidth[val] = fieldWidth[val] ? fieldWidth[val] : 100;	//默认宽度100px
				thStr += '<th><div style="width:' + fieldWidth[val] + 'px;">' + i + '</div></th>';
			})
			thStr += '</tr>';
			layer.open({
				type: 1,
				area: ['400px', '230px'],
				fix: false,
				offset: '10%',
				maxmin: true,
				shade: 0.3,
				title: '导入',
				content: $('#importTpl').html(),
				btn: ['<i class="dhicon dh-check"></i> 导入', '<i class="dhicon dh-remove"></i> 取消'],
				shadeClose: true,
				zIndex: 1000,
				btn1: function (index, layero) {
					var file = layero.find('#file');
					if (!file[0]['value']) {
						layer.msg("请选择文件！");
						return false;
					}
					var imRes = importListExcel(file[0], importFields, 'purchasestorage');
				}
			});
		} else {
			$.modal.alertWarning("后台未返回导入模板对象！");
		}
	}
 });


/*批量请求导入数据
     *tobj：导入数据对象
     *startNum：从第几条开始导入
     *oneImportNum：每次导入条数
     *allImportNum：总数据量
     *times：导入次数
     */
function eachImport(tobj,startNum, oneImportNum, allImportNum, times, timeNum){
	var importObj = [], inum = startNum, importBl='0%';
	for(var i = startNum; i < startNum + oneImportNum; i++){
		if(i >= allImportNum)break;
		inum = i + 1 ;
		importObj.push(tobj[i]);
	}
	$.ajaxSettings.async = false;
	$.post("/storage/productassemble/importdatapost", {'infoItems':JSON.stringify(importObj, null, 2)}, function(result) {
		importBl = (inum/allImportNum)*100;
		importObj = [];
		timeNum += 1;
		showloadings(false);
		layer.msg(result.msg)
		if(result.code==0){
			location.reload();
		}
	},"json");
}

//通过guid彻底删除
function remove(){
    var objpage=sessionStorage.getItem(moduleTable+'checkdata')
	if(!objpage){
		layer.msg("请先选择数据！");
	}else{
		$.modal.confirmCom('确定要删除么？',function(result){
	    	var infoItems=JSON.parse(objpage)
	    	$.operate.post('/storage/productassemble/delete',{infoItems:JSON.stringify(infoItems)},function(result){
	    		setTimeout(function(){
	    			table.reload('dhtable', {page: {curr: 1},where:getWherestr()});
	    		}, 1000);
	    	});
	    });
	}
}

</script>
</body>
</html>
